<script>

export default {
  name: 'VipExam',
  data () {
    return {
      formData: {
        email: '',
        idcard: '',
        idcard1: '',
        idcard2: '',
        nickname: '',
        userinfoId: '',
        username: ''
      },
      basePath: process.env.VUE_APP_BASE_PATH,
      show: false,
      idcard1Src: '',
      idcard2Src: ''
    }
  },
  methods: {
    init (id) {
      if (id) {
        this.$axios.get(`vip/info/${id}`).then(data => {
          this.formData = { ...data }
          this.idcard1Src = data.idcard1 ? this.basePath + data.idcard1 : ''
          this.idcard2Src = data.idcard2 ? this.basePath + data.idcard2 : ''
        }).catch(e => e)
      }
      this.show = true
    },
    submit (userinfoStatus) {
      this.$refs.formRef.validate(valid => {
        if (valid) {
          const content = userinfoStatus === 3 ? '同意' : '拒绝'
          const submitData = {
            userinfoStatus,
            userinfoId: this.formData.userinfoId,
            examContent: this.formData.examContent ? this.formData.examContent : content
          }
          this.$axios.post('userinfo/exam', submitData).then(() => {
            this.$message.success('审核完成！')
            this.show = false
            this.$emit('close')
          }).catch(e => e)
        }
      })
    }
  }
}
</script>

<template>
<el-dialog title="会员审核" :visible.sync="show" width="40%">
  <el-form :model="formData" ref="formRef" label-width="120px">
    <el-form-item label="用户名">
      <el-input v-model="formData.username" disabled/>
    </el-form-item>
    <el-form-item label="昵称">
      <el-input v-model="formData.nickname" disabled/>
    </el-form-item>
    <el-form-item label="邮箱">
      <el-input v-model="formData.email" disabled/>
    </el-form-item>
    <el-form-item label="身份证号">
      <el-input v-model="formData.idcard" disabled/>
    </el-form-item>
    <el-form-item label="身份证正面">
      <div class="avatar-uploader"><img :src="idcard1Src" class="avatar" alt="图片异常"></div>
    </el-form-item>
    <el-form-item label="身份证反面">
      <div class="avatar-uploader"><img :src="idcard2Src" class="avatar" alt="图片异常"></div>
    </el-form-item>
    <el-form-item label="审核意见">
      <el-input type="textarea" :rows="3" :maxlength="100" show-word-limit v-model="formData.examContent" placeholder="请输入审核意见"/>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="submit(3)">同意</el-button>
      <el-button type="danger" @click="submit(4)">拒绝</el-button>
    </el-form-item>
  </el-form>
</el-dialog>
</template>

<style scoped lang="scss">

</style>
